home *** CD-ROM | disk | FTP | other *** search
/ Free Software Collection: Marty 1 / FM Towns Marty 1 Free Software Collection.iso / joke / fugaku / source / kygload.c < prev   
Text File  |  1993-11-11  |  3KB  |  121 lines

  1. /*
  2.         --- Kyss presents ---
  3.         kygload.c : Kyss graphics format loader
  4.  
  5.         Last update : 1992-02-28  version 0.10
  6.  
  7.         for "TOWNS-GCC"
  8. */
  9.  
  10.  
  11. extern char egbwork[];
  12.  
  13. struct  /*  KYG format header ver.0.10 (128bytes)  */
  14. {             char  id[ 20 ];
  15.              char  message[ 80 ];
  16.     unsigned char  eom;
  17.     unsigned char  padding;
  18.     unsigned short xSize, ySize;
  19.     unsigned short xPosition, yPosition;
  20.     unsigned long  size;  /*  圧縮後のデータバイト数。ヘッダは含まないよん   */
  21.     unsigned short type;  /*  圧縮タイプ。0 は無圧縮、通常は 1
  22.                               はたして 2 以上が使われる日は・・・こないな    */
  23.     unsigned short color; /*  色数。たぶん 32768 しか使われんと思うけどね    */
  24.     char reserve[ 10 ];
  25. } KYGheader;
  26.  
  27.  
  28. int KYGload( char *fn, int mode, int page )
  29. {
  30.     int i;
  31.     int x, y;
  32.     int x1, y1;
  33.     int dp;
  34.     unsigned short base;
  35.     unsigned char count;
  36.     unsigned char rd;
  37.     unsigned char nrn;
  38.     unsigned long dataSize;
  39.     unsigned char  *iHeap;
  40.     unsigned short *oHeap;
  41.     FILE *ifp;
  42.     static int dps[] = { 0, 5, 2, 7, 4, 9, 1, 6, 3, 8 };
  43.  
  44.  
  45.     if( ( ifp = fopen( fn, "rb" ) ) == NULL )
  46.         return( ERR );
  47.     fread( &KYGheader, sizeof KYGheader, 1, ifp );
  48.     if( strncmp( KYGheader.id, "KYGformat", 9 ) != 0 )
  49.     {
  50.         printf( "not KYG format\n" );
  51.         return( ERR );
  52.     }
  53.     dataSize = KYGheader.xSize * KYGheader.ySize * 2;
  54.     if( ( oHeap = ( unsigned short * )( malloc( dataSize ) ) ) == NULL )
  55.         return( ERR );
  56.     if( ( iHeap = ( unsigned char * )( malloc( KYGheader.size ) ) ) == NULL )
  57.         return( ERR );
  58.     fread( iHeap, 1, KYGheader.size, ifp );
  59.     fclose( ifp );
  60.  
  61.     for( i = dp = nrn = 0; /*  dp < dataSize  */  i < dataSize / 2; )
  62.     {
  63.         if( ( rd = *( iHeap + dp ) & 0x0F ) == 0 || nrn > 0 )
  64.         {
  65.             if( nrn == 0 )
  66.                 nrn = ( *( iHeap + dp++ ) >> 4 ) - 1;
  67.             else
  68.                 --nrn;
  69.             base = *( unsigned short * )( iHeap + dp );
  70.             dp += 2;
  71.             count = ( ( base & 0x8000 ) != 0 ) ? 1 : *( iHeap + dp++ );
  72.             base &= 0x7FFF;
  73.         }
  74.         else
  75.         {
  76.             nrn = *( iHeap + dp++ ) >> 4;
  77.             count = ( ( rd & 0x08 ) != 0 ) ? 1 : *( iHeap + dp++ );
  78.             base = *( oHeap + i - KYGheader.xSize - 4 + ( rd & 0x07 ) );
  79.         }
  80.  
  81.         for( ; count > 0; --count, ++i )
  82.             *( oHeap + i ) = base;
  83.     }
  84.  
  85.     if( mode == 0 )
  86.     {
  87.         EGB_writePage( egbwork, page );
  88.         EGB_putRect( egbwork, 0, oHeap, KYGheader.xPosition, KYGheader.yPosition, KYGheader.xPosition + KYGheader.xSize - 1, KYGheader.yPosition + KYGheader.ySize - 1 );
  89.     }
  90.     else
  91.     {
  92.         for( y1 = 0; y1 < 10; ++y1 )
  93.         {
  94.             for( x1 = 0; x1 < 10; ++x1 )
  95.             {
  96.                 for( y = 0; y < 240; y += 10 )
  97.                 {
  98.                     for( x = 0; x < 320; x += 10 )
  99.                     {
  100.                         VRAM_putPixelW( ( x + dps[ x1 ] ) * 2 + ( y + dps[ y1 ] ) * 1024 + 0x40000 * page, *( oHeap + x + dps[ x1 ] + ( y + dps[ y1 ] ) * 320 ) );
  101.                     }
  102.                 }
  103.             }
  104.         }
  105.  
  106. /*        EGB_writePage( egbwork, page );
  107.         EGB_writeMode( egbwork, PASTEL );
  108.         for( i = 1; i <= 256; i += 5 )
  109.         {
  110.             EGB_pastel( egbwork, i );
  111.             EGB_putRect( egbwork, 0, oHeap, KYGheader.xPosition, KYGheader.yPosition, KYGheader.xPosition + KYGheader.xSize - 1, KYGheader.yPosition + KYGheader.ySize - 1 );
  112.         }
  113.         EGB_writeMode( egbwork, PSET );
  114. */
  115.     }
  116.  
  117.     free( iHeap );
  118.     free( oHeap );
  119.     return( 0 );
  120. }
  121.